package com.atguigu.java.ai.langchain4j;


import com.atguigu.java.ai.langchain4j.bean.ChatMessages;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;

@SpringBootTest
public class MongoMessage {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Test
    public void insertMessage() {
        ChatMessages chatMessages = new ChatMessages();
        chatMessages.setContent("你好!");
        mongoTemplate.insert(chatMessages);
    }

    @Test
    public void findMessage(){
        ChatMessages chatMessages = mongoTemplate.findById("681dc0e384d66111b285fc57", ChatMessages.class);
        System.out.println(chatMessages);
    }

    @Test
    public void updateMessage(){
        Criteria criteria = Criteria.where("_id").is("100");
        Query query = new Query(criteria);
        Update update = new Update();
        update.set("content", "你好");
        mongoTemplate.upsert(query, update, ChatMessages.class);
    }

    @Test
    public void deleteMessage(){
        Criteria criteria = Criteria.where("_id").is("100");
        Query query = new Query(criteria);
        mongoTemplate.remove(query, ChatMessages.class);
    }

}
